# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $$

inherit games

DESCRIPTION="NEXUIZ FPS"
HOMEPAGE="http://www.nexuiz.com"
SRC_URI="http://heanet.dl.sourceforge.net/sourceforge/nexuiz/nexuiz.zip"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~x86 ~amd64"
IUSE="sdl"

RDEPEND="sdl? ( media-libs/libsdl )
		virtual/opengl"

src_unpack() {
	unpack ${A}

	cd "${WORKDIR}/Nexuiz/sources"
	einfo "Unpacking engine sources"
	unzip nexuizenginesource20050530.zip 1>/dev/null
	cd "darkplaces"
	epatch $FILESDIR/compile-patch.diff
}

src_compile() {
	cd "${WORKDIR}/Nexuiz/sources/darkplaces"
	make cl-release sv-release \
		CFLAGS_RELEASE="" OPTIM_RELEASE="" CFLAGS_COMMON="$CFLAGS"
	cp nexuiz-dedicated nexuiz-glx ../..
	if use sdl
	then
		make sdl-release \
			CFLAGS_RELEASE="" OPTIM_RELEASE="" CFLAGS_COMMON="$CFLAGS"
		cp nexuiz-sdl ../..
	fi
}

src_install() {
	cd "${WORKDIR}/Nexuiz"
	
	dodir /opt/nexuiz
	exeinto /opt/nexuiz
	exeopts -m0755 -o $GAMES_USER -g $GAMES_GROUP
	doexe nexuiz-dedicated nexuiz-glx
	use sdl && doexe nexuiz-sdl
	
	dodir /opt/nexuiz/data
	insinto /opt/nexuiz/data
	insopts -m0644 -o $GAMES_USER -g $GAMES_GROUP
	doins data/*
	
	use sdl &&	games_make_wrapper nexuiz-sdl ./nexuiz-sdl			/opt/nexuiz
				games_make_wrapper nexuiz-glx ./nexuiz-glx			/opt/nexuiz
				games_make_wrapper nexuiz-ded ./nexuiz-dedicated	/opt/nexuiz
}

